package com.qiaofang.collectmanage.dao.impl;

import com.qiaofang.collectmanage.dao.SecretaryDao;
import com.qiaofang.collectmanage.dao.domain.SecretaryExtend;
import com.qiaofang.collectmanage.dao.elasticsearch.EsClient;
import com.qiaofang.collectmanage.dao.util.SecretaryDaoConvert;
import com.qiaofang.collectmanage.stub.constants.PlatFormEnum;
import com.qiaofang.collectmanage.stub.request.SecretaryRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author jingfa.sun
 */
@Service
public class SecretaryDaoImpl implements SecretaryDao {
    private static final Logger logger = LoggerFactory.getLogger(SecretaryDaoImpl.class);

    @Override
    public void crawlerSecretaryHouseInfo(SecretaryRequest secretaryRequest) {
        try {
            SecretaryDaoConvert secretaryDaoConvert = new SecretaryDaoConvert();
            List<SecretaryExtend> secretaryExtendList = secretaryDaoConvert.executeCrawlerTask(secretaryRequest);
            String beeTable = secretaryRequest.getBeeTable();
            String beeType = secretaryRequest.getBeeType();
            if (secretaryExtendList == null || secretaryExtendList.size() <= 0) {
                logger.info("统计{}数据{}", PlatFormEnum.BEE.getValue(), "爬取色" + secretaryRequest.getCollectType() + "房源数=0");
                return;
            }
            EsClient.addIndexBulkAddID(beeTable, beeType, secretaryExtendList);
            logger.info("统计{}数据{}", PlatFormEnum.BEE.getValue(), "爬取色" + secretaryRequest.getCollectType() + "房源数=" + secretaryExtendList.size());
        } catch (Exception ex) {
            logger.info("异常信息{}", ex);
        }
    }

}
